<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/6/27
 * Time: 21:56
 */
//是否显示
function is_show($attr,$module)
{
    return $module->$attr? '<span class="am-icon-check is_something" data-attr="'.$attr.'"></span>': '<span class="am-icon-close is_something" data-attr="'.$attr.'"></span>';
}


/**
 * 微信菜单, 删除空数组
 * @param $buttons
 */
function wechat_menus($request_buttons)
{
    $buttons = [];

    foreach ($request_buttons as $key => $value) {
        if ($value['name'] == "") {
            continue;  //如果一级菜单有name为空的 跳过
        }

        $buttons["$key"] = wechat_key_url($value);  //一级菜单key-url转换

        foreach ($value["sub_button"] as $k => $v) {  //二级菜单
            if ($v['name'] == "") {   //如果二级菜单有name为空的  跳过
                continue;
            }
            $buttons["$key"]["sub_button"][] = wechat_key_url($v);  //二级菜单key-url转换
        }
    }
    return $buttons;
}

/**
 * 根据类型,返回url或者key
 * @param $value
 * @return array
 */
function wechat_key_url($value)
{
    $result = [];

    $result['type'] = $value['type'];
    $result['name'] = $value['name'];
    if ($value['type'] == "click") {
        $result['key'] = $value['value'];
    } else {
        $result['url'] = $value['value'];
    }
    return $result;
}



/**
 * 订单状态
 * @param $status
 * @return mixed
 */
function order_status($status)
{
    $info = config('fangshop.order_status');
    return $info["$status"];
}

/**
 * 1=> '下单',       //待支付
 * 2=> '付款',       //待发货
 * 3=> '配货',
 * 4=> '出库',       //待收货
 * 5=> '交易成功',    //已完成
 */
function order_color($status)
{
    switch ($status) {
        case '1':
            return 'uc-order-item-pay';         //橙
            break;
        case '2':
            return 'uc-order-item-shipping';    //红
            break;
        case '3':
            return 'uc-order-item-shipping';    //红
            break;
        case '4':
            return 'uc-order-item-receiving';   //绿
            break;
        case '5':
            return 'uc-order-item-finish';      //灰
            break;
        default:
            return 'uc-order-item-finish';
    }
}


function time_format($attr, $datetime)
{
    if ($datetime == "") {
        return "";
    }
    return date($attr, strtotime($datetime));
}